import mock from '@/mock/mockInstance';
import { zh_CN, Faker } from '@faker-js/faker';
import { randomCarNumber, formatDateTime } from '@/utils/utils';

const customFaker = new Faker({ locale: zh_CN });

mock.onPost('/templatePage/StandardPage/getTableData').reply(() => {
  const data = [];
  const count = customFaker.number.int({ min: 1, max: 10 });
  for (let i = 0; i < count; i++) {
    data.push({
      id: i + 1,
      driverName: customFaker.person.fullName(),
      driverPhone: customFaker.phone.number(),
      carNumber: randomCarNumber(),
      carType: customFaker.helpers.arrayElement(['小型车', '中型车', '大型车']),
      isMeasure: customFaker.helpers.arrayElement([0, 1]),
      inDate: formatDateTime(customFaker.date.past()),
      outDate: formatDateTime(customFaker.date.future()),
      createTime: formatDateTime(customFaker.date.recent(), true),
      weightTime: formatDateTime(customFaker.date.recent(), true),
      updateTime: formatDateTime(customFaker.date.recent(), true),
      vehicleStatus: customFaker.helpers.arrayElement(['未进厂', '在厂内', '已离厂'])
    });
  }
  const params = {
    code: 200,
    msg: 'success',
    data: {
      total: count,
      list: data
    }
  };
  return [200, params];
});
